$(document).ready(function () {
    $('#allmap').css('height', $(window).height() + 'px');//窗口宽度
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(114.528729,37.983946);
    map.centerAndZoom(point, 14);
    var data_info = [
        { "x":114.528729 , "y":37.983946,"local":"科大新区" },
        { "x":114.520656 , "y":38.002373,"local":"师大新区" },
        { "x":114.553856 , "y":38.027376,"local":"河北地质大学" },
        { "x":114.505113 , "y":38.135113,"local":"经贸北校区" },
        { "x":114.466181 , "y":38.015912,"local":"汇华学院、经济管理学院" },
        { "x":114.519692 , "y":38.090858,"local":"铁道大学" },
        { "x":114.417322 , "y":37.891,   "local":"四方学院(南校区)" },
        { "x":114.607963 , "y":38.020579,"local":"石家庄学院" },
        { "x":114.471187 , "y":38.014768,"local":"河北外国语学院" },
        { "x":114.553856 , "y":38.027376,"local":"河北医科大学(本部、临床)" },
        { "x":114.553856 , "y":38.027376,"local":"河北地质大学华信学院" }
    ];
    var opts = {
        width : 150,     // 信息窗口宽度
        height: 30,     // 信息窗口高度
        title : "领航考研" , // 信息窗口标题
    };
    for(var i=0;i<data_info.length;i++){
        var marker = new BMap.Marker(new BMap.Point(data_info[i].x,data_info[i].y));  // 创建标注
        var content = "——"+data_info[i].local;
        map.addOverlay(marker); // 将标注添加到地图中
        addClickHandler(content,marker);
    }
    function addClickHandler(content,marker){
        marker.addEventListener("click",function(e){
            openInfo(content,e)}
        );
    }
    function openInfo(content,e){
        var p = e.target;
        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,point); //开启信息窗口
    }
    map.setCurrentCity("石家庄");// 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);//开启鼠标滚轮缩放
    $("table tr").each(function(){
        var tr = $(this);
        tr.click(function () {
            //初始化
            $("table tr").removeClass('clickBack');
            $("table tr td:first-child").removeClass('setFontColor')
            $("table tr td").find('.num-area').removeClass('clickBack')
            $("table").find('.num-area span').removeClass('setFontColor')
            tr.addClass('clickBack');
            //新增
            $(this).children().eq(0).addClass('setFontColor');
            tr.find('.num-area').addClass('clickBack')
            tr.find('.num-area span').addClass('setFontColor');
            // $("tr td:first-child").addClass('setFontColor')

            var tds = tr.find("td");
            tds.each(function(){
                var td = $(this);//alert(td.text());
                for(var i=0;i<data_info.length;i++){
                    if(td.text() === data_info[i].local){//alert(data_info[i].x)
                        map.centerAndZoom(new BMap.Point(data_info[i].x, data_info[i].y), 15);// 初始化地图,设置中心点坐标和地图级别
                        var content = "————"+data_info[i].local;
                        var infoWindow = new BMap.InfoWindow(content,opts);//创建信息窗口对象
                        var newPoint = new BMap.Point(data_info[i].x, data_info[i].y);
                        map.openInfoWindow(infoWindow,newPoint);//开启信息窗口
                    }
                }
            })
        })
    });

    // control height

    // $(window).resize(function() {
    //     $('#allmap').css('height', ($(document.body).height())-61 + 'px');
    // });
})